
<?php 

$form = $this->element;
$form->clearDecorators();
$form->addDecorator('Errors')->addDecorator('FormElements')
	->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
	->addDecorator('Form');
	
echo $form;

?>

<?
$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');
if(isset($id)){
?>
<br>
<br>
<b>Статистика показов</b>
<?
$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');

$db = Db::getConnection ();
		$sql = '
		select sum(day_count_click) as sumc,sum(day_count_show) as sums
		from banner_statistic
		where banner_id='.$id.' 
		';
		$rowTotal = $db->fetchAll ( $sql );

		$sql = '
		select *
		from banner_statistic
		where banner_id='.$id.' and dt=curdate()
		';
		$rowToday= $db->fetchAll ( $sql );
		?>
		<table border="1">
		<tr>
		<th>&nbsp;</th>
		<th>Показы</th>
		<th>Клики</th>
		<th>CTR</th>
		</tr>
		<tr>
		<td>Сегодня</td>
<?	$q_s = $q_c = $q = 0;
	if ($rowToday) {
		$q_s = $rowToday[0]["day_count_show"]>0 ? $rowToday[0]["day_count_show"]:0; 
		$q_c = $rowToday[0]["day_count_click"]>0 ? $rowToday[0]["day_count_click"]:0;
		$q = $rowToday[0]["day_count_show"] !=0 ? $rowToday[0]["day_count_click"]/ $rowToday[0]["day_count_show"]:0;
	}

	echo "<td>".$q_s."</td>";
	echo "<td>".$q_c."</td>";
	echo "<td>".$q."</td>";
?>
		</tr>
		<tr>
<? 	echo "<td>Всего</td>";
		$q_s = $rowTotal[0]["sums"]>0 ? $rowTotal[0]["sums"]:0; 
		$q_c = $rowTotal[0]["sumc"]>0 ? $rowTotal[0]["sumc"]:0; 
		echo "<td>".$q_s."</td>";
		echo "<td>".$q_c."</td>";
		$q = $rowTotal[0]["sums"] !=0 ? $rowTotal[0]["sumc"]/ $rowTotal[0]["sums"]:0;
		echo "<td>".$q."</td>";
?>
		</tr>
	</table>
<br>
<b>Получить отчет по баннеру</b>
<form action="/banners/getstatistic" style="margin-top:5px">
<table style="border:0px">
	<tr>
	<td>Дата начала периода:</td><td><input type="text" name="dt_from" class="date"></td>
	</tr>
	<tr>
	<td>Дата конца периода:</td><td><input type="text" name="dt_to" class="date"></td>
	</tr>
</table>
<?

echo '<input type="hidden" name="id" value = "'.$id.'">';
?>
	<input type="submit" value="Получить отчет">
</form>

<?}?>